<link rel="stylesheet" href="__PUBLIC_PACK__/layui/css/layui.css?v={:config('api.version')}" media="all">
<style>.storage-box{padding: 40px 0;background-color: #fff;}  .bottom-submit-box{padding-left:40px;}.download{display:none}.download span{cursor: pointer}</style>
<div class="storage-box">
    <form class="layui-form pt10" action="{:url()}" id="form" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-inline">
                <input type="hidden" value="{:request()->param()['app_id']}" name="app_id"/>
                <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="backSubmit">立即备份</button>
            </div>
        </div>
        <div class="layui-form-item download">
            <label class="layui-form-label"></label>
            <div class="layui-input-inline">
                <a href="#" class="downZip layui-btn layui-btn-primary">已备份, 点击此处下载</a>
            </div>
            <span uri="{:url('database/delzip')}" class="delZip" style="line-height: 40px;color:red">删除该备份文件</span>
        </div>
    </form>
</div>
<script src="__PUBLIC_PACK__/layui/layui.js?v={:config('api.version')}"></script>
<script>
    layui.use(['jquery','form'], function() {
        var $ = layui.jquery, layer = layui.layer, form = layui.form;
        form.on('submit(backSubmit)', function(data){
            let uri = $('#form').attr('action'),method = $('#form').attr('method');
            $.ajax({
                type: method,
                data:data.field,
                url: uri,
                success: function (res) {
                    if(res.code == 1){
                        $('.downZip').attr('href', res.data.file)
                        $('.download').show();
                    }
                }
            })
            return false;
        });
        $(document).on('click', '.delZip', function(){
            let uri = $(this).attr('uri'), file = $('.downZip').attr('href');
            $.ajax({
                type: 'post',
                data: {'zip':file},
                url: uri,
                success: function (res) {
                    layer.msg(res.msg);
                    if(res.code == 1){
                        $('.download').hide();
                    }
                }
            })
        })
    });
</script>